package com.dragon.string;

import java.io.UnsupportedEncodingException;

/**
 *
 * @author dragon
 * @since 2019/12/23
 */
public class Test1 {

    public static void main(String[] args) throws UnsupportedEncodingException {
        String a = "龙";
        // 对字符"龙"进行编码
        byte[] bytes = a.getBytes("UTF-8");
        for (byte aByte : bytes) {
            System.out.print(aByte + " ");
        }
        System.out.println();
        // 用GBK进行解码
        String b = new String(bytes, "GBK");
        System.out.println(b);
        // 用UTF-8进行解码
        String c = new String(bytes, "utf8");
        System.out.println(c);

        // 用 iso-8859-1进行编码
        String d = "潘";
        byte[] e = d.getBytes("iso-8859-1");
        // 用iso-8859-1进行解码
        String f = new String(e, "iso-8859-1");
        System.out.println(f);

    }
}
